/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React from 'react';
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  Text,
  StatusBar
} from 'react-native';

import { Provider } from 'react-redux';
import { createStore } from 'redux';
import friendReducer from './FriendReducer';

// import {createStackNavigator} from 'react-navigation-stack';
// import {createAppContainer} from 'react-navigation';
// import Home from './Home';
// import Friends from './Friends';
import Apps from './AppTabNavigator';
// import Apps from './AppStackNavigator';

// const AppStackNavigator = createStackNavigator({
//   Home: {screen: Home, params: {product: 'Playstation'}},
//   Friends: {screen: Friends, params: {product: 'Xbox'}},
// });

// const Apps = createAppContainer(AppStackNavigator);

const store = createStore(friendReducer);

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      currentFriends: ['AAA', 'BBB', 'CCC', 'DDD'],
      possibleFriends: ['Allie', 'Gator', 'Lizzie']
    };
  }

  addFriend = index => {
    const { currentFriends, possibleFriends } = this.state;

    // Pull friend out of possibleFriends
    const addedFriend = possibleFriends.splice(index, 1);

    // And put friend in currentFriends
    currentFriends.push(addedFriend);

    // Finally, update our app state
    this.setState({
      currentFriends,
      possibleFriends
    });
  };

  delFriend = index => {
    const { currentFriends, possibleFriends } = this.state;

    const deledFriend = currentFriends.splice(index, 1);

    possibleFriends.push(deledFriend);

    this.setState({
      currentFriends,
      possibleFriends
    });
  };

  render() {
    return (
      <Provider store={store}>
        <Apps
          screenProps={{
            currentFriends: this.state.currentFriends,
            possibleFriends: this.state.possibleFriends,
            addFriend: this.addFriend,
            delFriend: this.delFriend
          }}
        />
      </Provider>
    );
  }
}
